package j20251125;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class Demo1 {
    // 1. 从集合创建 (最常用)
    List<String> list = Arrays.asList("a", "b", "c");
    Stream<String> stream1 = list.stream(); // 顺序流
    Stream<String> stream2 = list.parallelStream(); // 并行流

    // 2. 从数组创建
    String[] array = {"a", "b", "c"};
    Stream<String> stream3 = Arrays.stream(array);

    // 3. 使用 Stream.of() 静态方法
    Stream<String> stream4 = Stream.of("a", "b", "c");

    // 4. 创建无限流 (常用于生成序列)
    Stream<Integer> stream5 = Stream.iterate(0, n -> n + 2); // 0, 2, 4, 6...
    Stream<Double> stream6 = Stream.generate(Math::random); // 无限个随机数
}
